1. Field of Invention
The present invention relates generally to the performance of garbage collection in object-based systems. More particularly, the present invention relates to enabling different garbage collectors to be implemented for use with a virtual machine substantially altering the virtual machine to support each garbage collector.
2. Description of the Related Art
Within an object-based environment, threads are often used to satisfy requests for services. A thread may be thought of as a xe2x80x9csketch padxe2x80x9d of storage resources, and is essentially a single sequential flow of control within a computer program. In general, a thread, or a xe2x80x9cthread of control,xe2x80x9d is a sequence of central processing unit (CPU) instructions or programming language statements that may be independently executed. Each thread in a multi-threaded environment has its own execution stack on which method activations reside. As will be appreciated by those skilled in the art, when a method is activated with respect to a thread, an activation is xe2x80x9cpushedxe2x80x9d on the execution stack of the thread. When the method returns, or is deactivated, the activation is xe2x80x9cpoppedxe2x80x9d from the execution stack. Since an activation of one method may activate another method, an execution stack operates in a first-in-last-out manner.
While maintaining multiple threads, a computing system may need to perform global operations which require synchronization, or control of all threads or a set of threads at a given time. One example of such a global operation is garbage collection. As will be appreciated by those skilled in the art, garbage collection is a method which allows memory storage associated with objects which are no longer alive to be automatically reclaimed.
Garbage collection generally occurs in two phases. A first phase typically involves identifying objects which are no longer needed or no longer in use, while a second phase renders the storage associated with the unneeded objects available for reallocation. An object in a program is needed, or alive, at a given time if a program may access the object in the future. When an object is such that it will not be accessed in the future the object is considered to be unneeded or dead. Garbage collection algorithms, or xe2x80x9cgarbage collectors,xe2x80x9d typically consider an object to be dead substantially only when a program has abandoned all pointers to the object, making future access to the object impossible.
Within systems which use garbage collectors, e.g., within systems which include virtual machines, when it is desired for a garbage collector to be modified or replaced with another garbage collector, the virtual machine itself must also be modified to support the modified or replacement garbage collector. At times, it may be desirable to replace an existing garbage collector in a system with a different garbage collector to improve the efficiency of garbage collection and, hence, the performance of the system. Typically, the process of altering or changing a garbage collector is time-consuming as it often requires substantial modifications be made to the virtual machine to accommodate the altered or new garbage collector.
Therefore, what is desired is a relatively inexpensive method and apparatus for enabling a garbage collector associated with a virtual machine to either be modified or changed. Specifically, what is needed is a method and an apparatus for enabling garbage collectors to be efficiently swapped into and swapped out of virtual machine systems.
The present invention relates to methods and apparatus for enabling modular garbage collectors to be swapped into and swapped out of virtual machines without requiring that the virtual machines be altered. According to one aspect of the present invention, an interface for reclaiming memory in a multi-threaded virtual machine environment that has a virtual machine includes a first module that is associated with the virtual machine and a second module that is separate from the first module but interfaces with the first module. The first module includes a first routine for initiating a garbage collection process within the virtual machine environment, a second routine for scanning roots associated with the virtual machine environment, and a third routine for following roots through objects associated with the virtual machine environment. The second module includes a fourth routine for initializing a heap in the virtual machine environment, a fifth routine for allocating an object in the virtual machine environment, and a sixth routine for performing the garbage collection process. In one embodiment, the second module also includes a seventh routine for implementing read and write barriers for the garbage collection process.
These and other advantages of the present invention will become apparent upon reading the following detailed descriptions and studying the various figures of the drawings.